home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / subst.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  3.5 KB  |  107 lines  |  [TEXT/ALFA]

  1. # Commands covered:  subst
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1994 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # SCCS: @(#) subst.test 1.8 97/06/23 18:20:15
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test subst-1.1 {basics} {
  18.     list [catch {subst} msg] $msg
  19. } {1 {wrong # args: should be "subst ?-nobackslashes? ?-nocommands? ?-novariables? string"}}
  20. test subst-1.2 {basics} {
  21.     list [catch {subst a b c} msg] $msg
  22. } {1 {wrong # args: should be "subst ?-nobackslashes? ?-nocommands? ?-novariables? string"}}
  23.  
  24. test subst-2.1 {simple strings} {
  25.     subst {}
  26. } {}
  27. test subst-2.2 {simple strings} {
  28.     subst a
  29. } a
  30. test subst-2.3 {simple strings} {
  31.     subst abcdefg
  32. } abcdefg
  33.  
  34. test subst-3.1 {backslash substitutions} {
  35.     subst {\x\$x\[foo bar]\\}
  36. } "x\$x\[foo bar]\\"
  37.  
  38. test subst-4.1 {variable substitutions} {
  39.     set a 44
  40.     subst {$a}
  41. } {44}
  42. test subst-4.2 {variable substitutions} {
  43.     set a 44
  44.     subst {x$a.y{$a}.z}
  45. } {x44.y{44}.z}
  46. test subst-4.3 {variable substitutions} {
  47.     catch {unset a}
  48.     set a(13) 82
  49.     set i 13
  50.     subst {x.$a($i)}
  51. } {x.82}
  52. catch {unset a}
  53. set long {This is a very long string, intentionally made so long that it
  54.     will overflow the static character size for dstrings, so that
  55.     additional memory will have to be allocated by subst.  That way,
  56.     if the subst procedure forgets to free up memory while returning
  57.     an error, there will be memory that isn't freed (this will be
  58.     detected when the tests are run under a checking memory allocator
  59.     such as Purify).}
  60. test subst-4.4 {variable substitutions} {
  61.     list [catch {subst {$long $a}} msg] $msg
  62. } {1 {can't read "a": no such variable}}
  63.  
  64. test subst-5.1 {command substitutions} {
  65.     subst {[concat {}]}
  66. } {}
  67. test subst-5.2 {command substitutions} {
  68.     subst {[concat A test string]}
  69. } {A test string}
  70. test subst-5.3 {command substitutions} {
  71.     subst {x.[concat foo].y.[concat bar].z}
  72. } {x.foo.y.bar.z}
  73. test subst-5.4 {command substitutions} {
  74.     list [catch {subst {$long [set long] [bogus_command]}} msg] $msg
  75. } {1 {invalid command name "bogus_command"}}
  76.  
  77. test subst-6.1 {clear the result after command substitution} {
  78.     catch {unset a}
  79.     list [catch {subst {[concat foo] $a}} msg] $msg
  80. } {1 {can't read "a": no such variable}}
  81.  
  82. test subst-7.1 {switches} {
  83.     list [catch {subst foo bar} msg] $msg
  84. } {1 {wrong # args: should be "subst ?-nobackslashes? ?-nocommands? ?-novariables? string"}}
  85. test subst-7.2 {switches} {
  86.     list [catch {subst -no bar} msg] $msg
  87. } {1 {bad switch "-no": must be -nobackslashes, -nocommands, or -novariables}}
  88. test subst-7.3 {switches} {
  89.     list [catch {subst -bogus bar} msg] $msg
  90. } {1 {bad switch "-bogus": must be -nobackslashes, -nocommands, or -novariables}}
  91. test subst-7.4 {switches} {
  92.     set x 123
  93.     subst -nobackslashes {abc $x [expr 1+2] \\\x41}
  94. } {abc 123 3 \\\x41}
  95. test subst-7.5 {switches} {
  96.     set x 123
  97.     subst -nocommands {abc $x [expr 1+2] \\\x41}
  98. } {abc 123 [expr 1+2] \A}
  99. test subst-7.6 {switches} {
  100.     set x 123
  101.     subst -novariables {abc $x [expr 1+2] \\\x41}
  102. } {abc $x 3 \A}
  103. test subst-7.7 {switches} {
  104.     set x 123
  105.     subst -nov -nob -noc {abc $x [expr 1+2] \\\x41}
  106. } {abc $x [expr 1+2] \\\x41}
  107.